package support.auth;

import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

//你就可以从数据库中读入用户的密码，角色信息，是否锁定，账号是否过期
@Service
public class MyUserDetailService implements UserDetailsService {
	// @Autowired
	// private PubUsersDao pubUsersDao;
	// @Autowired
	// private PubAuthoritiesResourcesDao pubAuthoritiesResourcesDao;

	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
		//
		// Collection<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
		// // 取得用户的权限
		// List<PubAuthorities> auth = pubUsersDao.findAuthByUserName(username);
		// String password = null;
		// // 取得用户的密码
		// password =
		// pubUsersDao.findUserByname(username).get(0).getUserPassword();
		//
		// List<PubAuthoritiesResources> aaa =
		// pubAuthoritiesResourcesDao.getAll();
		//
		// User user = new User(username, password, true, true, true, true, auths);
		
		//TODO: 查询用户信息获取用户所有授权码组成字符串序列，逗号分隔
		
		List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
		GrantedAuthority au = new GrantedAuthorityImpl("ROLE_ADMIN");
		auths.add(au);
		User user = new User(username, "111", true, true, true, true, auths);
		 
		return user;
	}

}
